﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace projectgame
{
    internal class ToolSeedChineseCabbage : ITool
    {
        public string Name { get; set; } = "seed_chinese_cabbage";

        public bool Selectable(ToolData toolData)
        {
            return toolData.ShowGrid[toolData.CellPos.x, toolData.CellPos.y] != null &&
                toolData.ShowGrid[toolData.CellPos.x, toolData.CellPos.y].HasPlant != true &&
                Global.ChineseCabbageSeedCount.Value > 0;
        }

        public void Use(ToolData toolData)
        {
            Global.ChineseCabbageSeedCount.Value--;
            var plantGameObj = ResController.Instance.PlantChineseCabbagePrefab
                                                     .Instantiate()//创建PlantPrefab种子的GameObject实例
                                                     .Position(toolData.GridCenterPos);//将PlantPrefab放入tileWorldPos位置

            var plant = plantGameObj.GetComponent<PlantChineseCabbage>();//获取植物对象上的plant组件对象给予plant
            plant.XCell = toolData.CellPos.x;
            plant.YCell = toolData.CellPos.y; //将地块坐标赋值给plant

            PlantController.Instance.Plants[toolData.CellPos.x, toolData.CellPos.y] = plant;//将plant对象传回Plants数组对应位置

            toolData.ShowGrid[toolData.CellPos.x, toolData.CellPos.y].HasPlant = true; //设置玩家当前位置地块的SoilData.HasPlant属性为true

            AudioController.Get.SfxPutSeed.Play();
        }
    }
}
